package com.woniuxy.platform.core.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.CommonResult;
import com.woniuxy.platform.core.model.PmComplain;
import com.woniuxy.platform.core.service.PmComplainService;
import com.woniuxy.platform.core.vo.PmComplainVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-07-08
 */
@RestController
@RequestMapping("/pmComplain")
@Api(tags = "投诉信息管理")
public class PmComplainController {

    @Resource
    private PmComplainService pmComplainService;


    @GetMapping("selectComplain")
    @ApiOperation("获取投诉数据")
    public CommonResult<PageInfo<PmComplain>> selectComplain(int startpage , int pagesize){
        PageHelper.startPage(startpage,pagesize);
        Page<PmComplain> page =(Page<PmComplain>) this.pmComplainService.selectComplain();
        PageInfo<PmComplain> complainPageInfo = new PageInfo<>(page);
        return CommonResult.success(complainPageInfo);
    }

    @PostMapping("selectMH")
    @ApiOperation("投诉数据模糊查询")
    public CommonResult<PageInfo<PmComplain>> selctMH(@RequestBody PmComplainVo pmComplainVo){
        PageHelper.startPage(pmComplainVo.getPage(),pmComplainVo.getLimit());
        Page<PmComplain> page = (Page<PmComplain>) this.pmComplainService.selectMH(pmComplainVo.getPmComplain());
        PageInfo<PmComplain> pmComplainPageInfo = new PageInfo<>(page);
        return CommonResult.success(pmComplainPageInfo);
    }


    @PostMapping("updateDispose")
    @ApiOperation("更改受理类型")
    public CommonResult updateDispose(@RequestBody PmComplain pmComplain){
        int i = this.pmComplainService.updateDispose(pmComplain);
        if (i > 0){
            return CommonResult.success();
        }
        return CommonResult.fail();
    }


    @PostMapping("insertComplain")
    @ApiOperation("增加投诉")
    public CommonResult insertComplain(@RequestBody PmComplain pmComplain){
        int i = this.pmComplainService.insertComplain(pmComplain);
        if (i >0){
            return CommonResult.success();
        }
        return CommonResult.fail();
    }
}

